/*
 * Created by JFormDesigner on Mon Jun 03 16:17:30 EDT 2013
 */

package MaintMenu.SyncInventoryToCat;


import MaintMenu.PoAnalysis.*;
import MaintMenu.VenPricingUpdMasterFiles.*;
import MaintMenu.VenPricingUpdMasterFiles.Trn6Category;
import MaintMenu.VenPricingUpdTBLN.*;
import MaintMenu.VendorCostPreProcess;
import MaintMenu.timerSql;

import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.event.*;

/**
 * @author Jason Chi
 */
public class SyncInventoryToCat extends JPanel {
    public SyncInventoryToCat() {
        initComponents();
    }

    private void buttonYCCActionPerformed(ActionEvent e) {
        // TODO add your code here
    }

    private void updateCAPAActionPerformed(ActionEvent e) {
        // TODO add your code here
    }

    private void updateCAPAStateChanged(ChangeEvent e) {
        // TODO add your code here
    }

    private void buttonTESTActionPerformed(ActionEvent e) {
        // TODO add your code here
    }

    private void buttonAPActionPerformed(ActionEvent e) {
        // TODO add your code here
    }

    private void updInvFromCatActionPerformed(ActionEvent e) {
        // TODO add your code here
    }

    private void updInvFromCatStateChanged(ChangeEvent e) {
        // TODO add your code here
    }

    private void UPDINVPLActionPerformed(ActionEvent e) {
        UpdateTblinventoryPLfrom6Cats sql1 = new UpdateTblinventoryPLfrom6Cats();
//        JOptionPane.showMessageDialog(null,"UpdateTblinventoryPLfrom6Cats Complete");
    }

    private void CAPActionPerformed(ActionEvent e) {
        UpdCapa updCapa = new UpdCapa();
//        JOptionPane.showMessageDialog(null,"CAPA Complete");
    }

    private void LIinvToBKinvActionPerformed(ActionEvent e) {
        UpdateBKtblinventoryWithLItbinventory updateBKtblinventoryWithLItbinventory = new UpdateBKtblinventoryWithLItbinventory();
//        JOptionPane.showMessageDialog(null,"Update (BK inv) with (LI inv) Complete");
    }

    private void InsertItemFromINVtoCATActionPerformed(ActionEvent e) {
        InsertNewItemInTblinventoryTo6Mast insertNewItemInTblinventoryTo6Mast = new InsertNewItemInTblinventoryTo6Mast();
//        JOptionPane.showMessageDialog(null,"Insert item from INV to CATs Complete");
    }

    private void invToCatCompleteActionPerformed(ActionEvent e) {
        timerSql timerSql = new timerSql();
        timerSql.setbTime();
        //update Vendor Cost sheet receives from mail. _costdepo1-4 adds CAPA and PARTSLINK field and isolates.
        VendorCostPreProcess vc = new VendorCostPreProcess("DP",4);


        //Updatate PL from 6 Cats to TblInventory
//        System.out.println("\nStep 1: Updatate PL# from 6 Cats to TblInventory");
        UpdateTblinventoryPLfrom6Cats updateTblinventoryPLfrom6Cats = new UpdateTblinventoryPLfrom6Cats();

        //step 1. tblInventory to ??MAST  (i.e.OTMAST)
//        System.out.println("\nStep 1.1: Insert new item from tblInventory to ??MAST  (i.e.OTMAST)\n");
        InsertNewItemInTblinventoryTo6Mast insertNewItemInTblinventoryTo6Mast = new InsertNewItemInTblinventoryTo6Mast();

//        System.out.println("Step 1.5: delete all pricing");
        delTblnCost delTblnCost = new delTblnCost();

        //Step 2. Update Vendor goods information based on partslink#(Price,Part#,Package etc) to ??MAST   (i.e.OTMAST)
        //System.out.println("\nStep 2: Update Vendor goods information based on partslink#(Price,Part#,Package etc) to ??MAST   (i.e.OTMAST)");
        AP ap= new AP();
        //System.out.print("AP Complete");
        YCC ycc= new YCC();
        //System.out.print(" . YCC Complete");
        TYGtw tyGtw = new TYGtw();
        //System.out.print(" . TW Complete");
        TYGtx tyGtx = new TYGtx();
        //System.out.print(" . TX Complete");
        GENERA gen = new GENERA();
        //System.out.print(" . GN Complete");
        DEPO depo1 = new DEPO();
        //System.out.println(" . DP Complete");

        //Step 3. Transfer ??MAST to TBL??N (ie. OTMAST to TBLOTN)
        //System.out.println("\nStep 3: Transfer ??MAST to TBL??N (ie. OTMAST to TBLOTN)");
        Trn6Category trn6Category = new Trn6Category();

        //Step 4. Update TBL??N item info with Vendor's data. (price, otem#,ven#,cuft etc.)
        //System.out.println("\nStep 4: Update TBL??N item info with Vendor's data. (price, otem#,ven#,cuft etc.");

        APtbl ap1= new APtbl(0);
        //System.out.println("\nAP Complete\n");
        YCCtbl ycc1= new YCCtbl(0);
        //System.out.println("\nYCC Complete\n");
        TYGtwtbl tyGtw0 = new TYGtwtbl(0);
        TYGtwtbl tyGtw1 = new TYGtwtbl(1);
        //System.out.println("\nTW Complete\n");
        TYGtxtbl tyGtx0 = new TYGtxtbl(0);
        TYGtxtbl tyGtx1 = new TYGtxtbl(1);
        //System.out.println("\nTX Complete\n");
        GENERAtbl gen1 = new GENERAtbl(1);
        //System.out.println("\nGN Complete\n");
        DEPOtbl depo11 = new DEPOtbl(0);
        //System.out.println("\nDP Complete\n");
//        JOptionPane.showMessageDialog(null, "Execute Complete");


        //Step 5. POAnalysis 3 days



        DateRange dateRange = new DateRange();
        String f = dateRange.threeDayBack();

        String t = dateRange.yesterday();
        BCAnalysis bcAnalysis = new BCAnalysis(f, t);
        //System.out.print("bc done\t");
        CLAnalysis clAnalysis = new CLAnalysis(f, t);
        //System.out.print("cl done\t");
        HFAnalysis hfAnalysis = new HFAnalysis(f, t);
        //System.out.print("hf done\t");
        LTAnalysis ltAnalysis = new LTAnalysis(f, t);
        //System.out.print("lt done\t");
        MRAnalysis mrAnalysis = new MRAnalysis(f, t);
        //System.out.print("mr done\t");
        OTAnalysis otAnalysis = new OTAnalysis(f, t);
        //System.out.println("ot done");


        //NEW UPDATE PRICE BY PART#  (This should be by default since all items has DNK part#)

        //System.out.println("NEW UPDATE PRICE BY PART#  (This should be by default since all items has DNK part#)");
        VendorCostUpd  upd2a  = new VendorCostUpd("HF",1);
        VendorCostUpd  upd1a  = new VendorCostUpd("OT",1);
        VendorCostUpd  upd3a  = new VendorCostUpd("BC",1);
        VendorCostUpd  upd4a  = new VendorCostUpd("CL",1);
        VendorCostUpd  upd5a  = new VendorCostUpd("MR",1);
        VendorCostUpd  upd6a  = new VendorCostUpd("LTLI",1);
        VendorCostUpd  upd7a  = new VendorCostUpd("LTBK",1);


        String timeReport = "Process took :"+timerSql.gettTime();
        System.out.println(timeReport);

//        JOptionPane.showMessageDialog(null,"Completed with 3 days POAnalysis. Ready for PoAnalysis export.");

    }





    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        // Generated using JFormDesigner Evaluation license - jason Chi
        label1 = new JLabel();
        updInvFromCat = new JButton();
        label2 = new JLabel();
        updateCAPA = new JButton();
        label3 = new JLabel();
        buttonTEST = new JButton();
        LIinvToBKinv = new JButton();
        InsertItemFromINVtoCAT = new JButton();
        invToCatComplete = new JButton();

        //======== this ========

        // JFormDesigner evaluation mark
        setBorder(new javax.swing.border.CompoundBorder(
            new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
                "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
                javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
                java.awt.Color.red), getBorder())); addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});


        //---- label1 ----
        label1.setText("Vendor Pricing Update");

        //---- updInvFromCat ----
        updInvFromCat.setText("Update Inventory PL from Categories, Then INV PL to MAST");
        updInvFromCat.setToolTipText("Based on the  matching [PART#], the system will copy PartsLink # from all 6 CAT (i.e. tblbcn) to TBLinventory.");
        updInvFromCat.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                UPDINVPLActionPerformed(e);
            }
        });

        //---- updateCAPA ----
        updateCAPA.setText("Update Tblinventory.capa by DNK# ending with QQ");
        updateCAPA.setToolTipText("Go throught TBLinventory and check for DNK#. If any DNK PART# include \"Q\", but not \"QQ\". the system will mark it as CAPA");
        updateCAPA.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CAPActionPerformed(e);
            }
        });

        //---- buttonTEST ----
        buttonTEST.setText("TEST");
        buttonTEST.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                buttonTESTActionPerformed(e);
            }
        });

        //---- LIinvToBKinv ----
        LIinvToBKinv.setText("Updates INV (BK) with INV (LI)");
        LIinvToBKinv.setToolTipText("Not finish");
        LIinvToBKinv.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                LIinvToBKinvActionPerformed(e);
            }
        });

        //---- InsertItemFromINVtoCAT ----
        InsertItemFromINVtoCAT.setText("Insert New items from INV to 6 Master files Only (ie.OTmast) ");
        InsertItemFromINVtoCAT.setToolTipText("Check if [PART#] exists in CATS, if not insert INV item to CAT.  \nCheck catelogy [PART#] belongs to.");
        InsertItemFromINVtoCAT.setBackground(Color.red);
        InsertItemFromINVtoCAT.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                InsertItemFromINVtoCATActionPerformed(e);
            }
        });

        //---- invToCatComplete ----
        invToCatComplete.setText("New Items to 6 Cats with vendor updates ( Complete Prep for Poanalysis)");
        invToCatComplete.setToolTipText("Complete process to Sync new items inTBLINV to 6 Cats (prep for Poanalysis)\n1) Update PL from 6 Cats to TBLInventory\n2) Insert items from Inventory to Mast if doesn't exisit\n3) Update Item information from Vendor's updates (price,pkg,cu/ft etc.) \n4) Transfer Mast to Cats\n");
        invToCatComplete.setBackground(new Color(0, 153, 51));
        invToCatComplete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                invToCatCompleteActionPerformed(e);
            }
        });

        GroupLayout layout = new GroupLayout(this);
        setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup()
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup()
                        .addGroup(layout.createSequentialGroup()
                            .addGap(194, 194, 194)
                            .addComponent(label1))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup()
                                .addComponent(updateCAPA)
                                .addComponent(updInvFromCat, GroupLayout.PREFERRED_SIZE, 409, GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup()
                                .addComponent(label3, GroupLayout.PREFERRED_SIZE, 123, GroupLayout.PREFERRED_SIZE)
                                .addComponent(label2, GroupLayout.PREFERRED_SIZE, 123, GroupLayout.PREFERRED_SIZE)))
                        .addComponent(buttonTEST, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE)
                        .addComponent(LIinvToBKinv, GroupLayout.PREFERRED_SIZE, 234, GroupLayout.PREFERRED_SIZE)
                        .addComponent(InsertItemFromINVtoCAT)
                        .addComponent(invToCatComplete))
                    .addGap(42, 42, 42))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup()
                .addGroup(layout.createSequentialGroup()
                    .addComponent(label1)
                    .addGap(5, 5, 5)
                    .addGroup(layout.createParallelGroup()
                        .addComponent(label2, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
                        .addComponent(updInvFromCat))
                    .addGroup(layout.createParallelGroup()
                        .addGroup(layout.createSequentialGroup()
                            .addGap(5, 5, 5)
                            .addComponent(updateCAPA))
                        .addGroup(layout.createSequentialGroup()
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(label3, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(LIinvToBKinv)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(InsertItemFromINVtoCAT)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE)
                    .addComponent(invToCatComplete)
                    .addGap(81, 81, 81)
                    .addComponent(buttonTEST)
                    .addGap(14, 14, 14))
        );
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    // Generated using JFormDesigner Evaluation license - jason Chi
    private JLabel label1;
    private JButton updInvFromCat;
    private JLabel label2;
    private JButton updateCAPA;
    private JLabel label3;
    private JButton buttonTEST;
    private JButton LIinvToBKinv;
    private JButton InsertItemFromINVtoCAT;
    private JButton invToCatComplete;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
